﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/js/common.js"></script>
<script>
    $(function () {
        $("#seProvence").change(function () {
            var Parent = $(this).val();
            if ($("#seCity").find("option").length > 0) {
                $("#seCity").empty();
            }
            if ($("#seQu").find("option").length > 0) {
                $("#seQu").empty();
            }
            GetCity(Parent);
        });
        $("#seCity").change(function () {
            var Parent = $(this).val();
            if ($("#seQu").find("option").length > 0) {
                $("#seQu").empty();
            }
            GetQu(Parent);
        });
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: "00000000-0000-0000-0000-000000000000" },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seProvence").append("<option>选择省份</option>");
                $.each(data, function (i) {
                    $("#seProvence").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
        gridList();
    })
    function gridList() {
        var SelectRowIndx;
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/Shop/GetGridJson",
            height: $(window).height() - 128,
            colModel: [
                { label: '主键', name: 'ShopGuid', hidden: true },
                { label: '店面名称', name: 'ShopName', width: 100, align: 'left' },
                { label: '店面地址', name: 'Address', width: 150, align: 'left' },
                {
                    label: '经纬度', name: 'JingWei', width: 150, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.Lng + "," + rowObject.Lat;
                    }
                },
                {
                    label: '开业时间', name: 'SetUpTime', width: 66, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.SetUpTime).format("yyyy-MM-dd"));
                    }
                },
                {
                    label: '营业时间', name: 'SetUpTime', width: 80, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return (new Date(rowObject.OpenStartTime)).format("hh:mm") + "~" + (new Date(rowObject.OpenEndTime)).format("hh:mm");
                    }
                },
                  { label: '添加者', name: 'AddPerson', width: 80, align: 'left' },
                 {
                     label: '添加时间', name: 'AddTime', width: 120, align: 'left',
                     formatter: "date", formatoptions: { srcformat: 'Y-m-d h:m:s', newformat: 'Y-m-d h:m:s' }
                 },
                 { label: '修改者', name: 'ModifyPerson', width: 80, align: 'left' },
                 {
                     label: '修改时间', name: 'ModifyDate', width: 120, align: 'left',
                     formatter: "date", formatoptions: { srcformat: 'Y-m-d h:m:s', newformat: 'Y-m-d h:m:s' }
                 },
                     {
                         label: '是否显示', name: 'IsShow', width: 60, align: 'center',
                         formatter: function (cellvalue, options, rowObject) {
                             if (cellvalue == 1) {
                                 return '显示';
                             } else {
                                 return '不显示';
                             }
                         }
                     },
                     {
                         label: '是否营业', name: 'IsOpen', width: 60, align: 'center',
                         formatter: function (cellvalue, options, rowObject) {
                             if (cellvalue == 1) {
                                 return '营业';
                             } else {
                                 return '不营业';
                             }
                         }
                     }
            ],
            pager: "#gridPager",
            //sortname: 'UpdateTime desc,ID desc',
            //multiselect: false,
            multiselect: true,
            multiboxonly: true,
            beforeSelectRow: beforeSelectRow,//js方法  
            sortname: 'UpdateTime desc',
            viewrecords: true,
            onSelectRow: function () {
                SelectRowIndx = GetJqGridRowIndx("#" + this.ShopGuid);
            },
            gridComplete: function () {
                $("#" + this.ShopGuid).jqGrid('setSelection', SelectRowIndx);
            }
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: {
                    keyword: $("#txt_keyword").val(),
                    pri: $("#seProvence").val() == "选择省份" ? "" : $("#seProvence").val(),
                    City: $("#seCity").val() == "选择城市" ? "" : $("#seCity").val(),
                    Qu: $("#seQu").val() == "选择地区" ? "" : $("#seQu").val()
                },
            }).trigger('reloadGrid');
        });
    }
    function beforeSelectRow() {
        $("#jqgridId").jqGrid('resetSelection');
        return (true);
    }
    //function btn_edit() {
    //    var keyValue = $("#gridList").jqGridRowValue().ID;
    //    $.modalOpen({
    //        id: "Form",
    //        title: "修改人员信息",
    //        url: "/Actor/Form?keyValue=" + keyValue,
    //        width: "800px",
    //        height: "910px",
    //        callBack: function (iframeId) {
    //            top.frames[iframeId].submitForm();
    //        }
    //    });
    //}
    function getSelectInfo() {
        var obj = new Object();
        var selr = jQuery('#gridList').jqGrid('getGridParam', 'selarrrow');
        if (selr.length) {
            var myrow = jQuery('#gridList').jqGrid('getRowData', selr);
            obj.ShopGuid = myrow.ShopGuid;
            obj.ShopName = myrow.ShopName;
        }
        return obj;
    }
    function GetCity(tem) {
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: tem },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seCity").append("<option></option>");
                $.each(data, function (i) {
                    $("#seCity").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
    }
    function GetQu(tem) {
        $.ajax({
            url: "/ItemsType/GetChildListByParentID",
            data: { keyValue: tem },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#seQu").append("<option></option>");
                $.each(data, function (i) {
                    $("#seQu").append($("<option></option>").val(data[i].id).html(data[i].text));
                });
            }
        });
    }
</script>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="店面名称" style="width: 200px;" maxlength="25">
                        <select id="seProvence" name="seProvence" class="form-control" style="width: 120px;  margin-left: 10px;"></select>
                        <select id="seCity" name="seCity" class="form-control" style="width: 120px; margin-left:10px;"></select>
                        <select id="seQu" name="seQu" class="form-control" style="width: 120px;   margin-left: 10px; "></select>
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
